package com.example.idachuappone.index.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery.LayoutParams;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

import com.example.idachuappone.R;
import com.example.idachuappone.utils.BitmapUtilHelper;
import com.lidroid.xutils.BitmapUtils;

public class ImgAdapter extends BaseAdapter {
	private Context _context;
	private BitmapUtils bu;
	private List<String> imgList;

	private class ViewHolder {
		ImageView imageView;

		private ViewHolder() {
		}
	}

	public ImgAdapter(Context context, List<String> imgList) {
		this._context = context;
		this.imgList = imgList;
		this.bu = BitmapUtilHelper.createBitmapUtil(this._context);
	}

	@Override
	public int getCount() {
		return Integer.MAX_VALUE;
	}

	@Override
	public Object getItem(int position) {
		return Integer.valueOf(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			ImageView imageView = new ImageView(this._context);
			imageView.setAdjustViewBounds(true);
			imageView.setScaleType(ScaleType.FIT_XY);
			imageView.setBackgroundColor(this._context.getResources().getColor(R.color.trans));
			imageView.setLayoutParams(new LayoutParams(-1, -1));
			convertView = imageView;
			viewHolder.imageView = (ImageView) convertView;
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		this.bu.display(viewHolder.imageView, this.imgList.get(position % this.imgList.size()));
		return convertView;
	}
}
